using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Reflection;

namespace DynamicGeneration.Modules.WebApiExplorer
{
    // CLEAN:
    //public class RouteValueInfo
    //{
    //    public string Key { get; set; }
    //    public object Value { get; set; }
    //}

    public class ControllerInfo
    {
        private const string Suffix = "Controller";
        public Type ControllerType { get; set; }
        public List<WebApiMethodInfo> Methods { get; set; }
        public string Namespace { get { return ControllerType.Namespace; } }
        public string Name { get { return ControllerType.Name; } }
        public string ShortName { get { return Name != null && Name.EndsWith(Suffix) ? Name.Substring(0, Name.Length - Suffix.Length) : Name; } }

        public ControllerInfo(Type controller)
        {
            // Any class in the namespace with a name ending in "Controller" that has methods returning a WebResponseMessage type
            ControllerType = controller;
            var meth = ControllerType.GetMethods().Where<MethodInfo>(_ => _.ReturnType.Equals(typeof(HttpResponseMessage)));
            Methods = (from item in meth
                       select new WebApiMethodInfo(item) { }).ToList<WebApiMethodInfo>();

        }
    }
}
